<cfparam name="playerresult.recordCount" default="">

<cfset homeTeamRubbers = 0>
<cfset awayTeamRubbers = 0>
<cfset homeTeamGames = 0>
<cfset awayTeamGames = 0>

<cfoutput>

	<h3>#homeTeam.TeamName# (#linkTo(text="view", route="redirecter", controller="teams", action="display", key=homeTeam.TeamID, params="SeasonID=#params.SeasonID#")#)
		
		vs.
		
		#awayTeam.TeamName# (#linkTo(text="view", route="teams", action="display", key=awayTeam.TeamID)#)</h3>
	
	
	<table class="nostyle">
		<tr>
			<td colspan="3" style="text-align:center">Home Team</td>
			<td colspan="3" style="text-align:center">Away Team</td>
			<td></td>
		</tr>
		<tr>
			<th>No</th>
			<th>Player</th>
			<th>Score</th>
			<th>No</th>
			<th>Player</th>
			<th>Score</th>
			<th>Actions</th>
		</tr>
		<cfloop query="tmp" startrow="1" endrow="#tmp.recordCount#">
			<tr>
				<td>#tmp.homePosition#</td>
				<td>#tmp.homePlayerID# #tmp.homeFirstName# #tmp.homeLastName#</td>
				<td>#tmp.homePlayerGames#</td>
				<td>#tmp.awayPosition#</td>
				<td>#tmp.awayPlayerID# #tmp.awayFirstName# #tmp.awayLastName#</td>
				<td>#tmp.awayPlayerGames#</td>
				<td>
					#tmp.fixtureID#
					#tmp.SeasonID#
					#tmp.PlayerResultID#
				</td>
			</tr>
		</cfloop>
		
		
		<cfloop from="1" to="3" index="x">
		
		
		
		<!---<cfloop query="homeTeamPlayers" startrow="1" endrow="#homeTeamPlayers.recordCount#">--->
		#startFormTag(controller="playerresults", action="update", key=playerresult.playerresultid[#x#],name="playerResults_#x#")#
			#hiddenFieldTag(name='playerResult[resulted]',value=Now())#
			
		<tr>
			<td>#homeTeamPlayers.Position[x]#</td>
		
			<td>
				#homeTeamPlayers.PlayerID[x]#
				
				#homeTeamPlayers.FirstName[x]#
				#homeTeamPlayers.LastName[x]#
			</td>
		
			<td>
				#textFieldTag(name='playerResult[homePlayerGames]', value=playerresult.homeplayergames[#x#])#
				<cfif Len(playerresult.homeplayergames[#x#])>
					<cfset homeTeamGames = homeTeamGames + playerresult.homeplayergames[#x#]>
				</cfif>

				<cfif Len(playerresult.homeplayergames[x]) AND playerresult.homeplayergames[x] GTE 6>
					<cfset homeTeamRubbers = homeTeamRubbers + 1>
				</cfif>
			</td>
			<td>
				#awayTeamPlayers.Position[x]#
			</td>
			<td>
				#awayTeamPlayers.PlayerID[x]#		
				
				#awayTeamPlayers.FirstName[x]#
				#awayTeamPlayers.LastName[x]#
	 		</td>
	 		<td>
				#textFieldTag(name='playerResult[awayPlayergames]', value=playerresult.awayplayergames[#x#])#	
				<cfif Len(playerresult.awayplayergames[#x#])>
					<cfset awayTeamGames = awayTeamGames+  playerresult.awayplayergames[#x#]>
				</cfif>
				
				<cfif Len(playerresult.awayplayergames[x]) AND playerresult.awayplayergames[x] GTE 6>
					<cfset awayTeamRubbers = awayTeamRubbers + 1>
				</cfif>
			</td>
			<td>
				<cfif Len(playerresult.resulted[x])>
					<!--- Score submitted --->
				<cfelse>
					#submitTag(value="Enter Score",disable="Please wait...")#
					
					#playerresult.playerresultid[#x#]#
				</cfif>
			</td>
		</tr>
		#endFormTag()#
		</cfloop>	
		<tr>
			<td colspan="7">&nbsp;</td>
		</tr>	
		<tr>
			<td colspan="2">Total Games</td>
			<td>#homeTeamGames#</td>
			<td colspan="2">Total Games</td>
			<td>#awayTeamGames#</td>
			<td></td>
		</tr>
		<tr>
			<td colspan="2">Total Rubbers</td>
			<td>#homeTeamRubbers#</td>
			<td colspan="2">Total Rubbers</td>
			<td>#awayTeamRubbers#</td>
			<td></td>
		</tr>
		<cfset homeTeamPoints = homeTeamRubbers>
		<cfset awayTeamPoints = awayTeamRubbers>
		
		<cfif homeTeamRubbers GT awayTeamRubbers>
			<cfset homeTeamPoints = homeTeamPoints + 2>
		<cfelse>
			<cfset awayTeamPoints = awayTeamPoints + 2>
		</cfif>
		
		<tr>
			<td colspan="2"><strong>Total Points</strong></td>
			<td>#homeTeamPoints#</td>
			<td colspan="2"><strong>Total Points</strong></td>
			<td>#awayTeamPoints#</td>
			<td></td>
		</tr>
		<tr>
			<td colspan="7">
				<cfif isObject(result)>
					#startFormTag(action="update",key=result.resultid)#							
				<cfelse>
					#startFormTag(action="create")#							
				</cfif>

					#hiddenFieldTag(name="result[fixtureId]",value="#params.key#")#
					#hiddenFieldTag(name="result[seasonId]",value="#params.SeasonID#")#
					#hiddenFieldTag(name="result[homeTeamPoints]",value="#homeTeamPoints#")#
					#hiddenFieldTag(name="result[awayTeamPoints]",value="#awayTeamPoints#")#
					#hiddenFieldTag(name="result[homeTeamGames]",value="#homeTeamGames#")#
					#hiddenFieldTag(name="result[awayTeamGames]",value="#awayTeamGames#")#
					<cfif isObject(result)>
						#submitTag(value="Update Scorecard",disable="Please wait...")#
					<cfelse>
						#submitTag(value="Submit Scorecard",disable="Please wait...")#
					</cfif>
				#endFormTag()#
			</td>
		</tr>
	</table>
	<br /><br />
</cfoutput>